/*
 * @Description: 
 * @Version: 
 * @Author: Code Boy
 * @Date: 2021-01-28 09:04:10
 * @LastEditors: Code Boy
 * @LastEditTime: 2021-08-17 14:39:14
 */
#include <string.h>
#include <sys/param.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "tcpip_adapter.h"
#include "protocol_examples_common.h"

#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include <lwip/netdb.h>

#include "driver/gpio.h"

#include "m_http_client.h"
#include "m_ethernet.h"
#include "m_wifi.h"
#include "m_uart.h"
#include "m_ble.h"
#include "m_nvs.h"
#include "m_led.h"
#include "m_config.h"

ble_esp32_param_t m_ble_esp32_param;

void app_main(void)
{
    ESP_ERROR_CHECK(nvs_flash_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());

    mmware_hardware_reset();

    led_init();

    ble_init();

    //mUart_init();

    nvs_read_ble_param_information(&m_ble_esp32_param);
    if(!m_ble_esp32_param.ble_char1_WifiName_len)
    {
        m_ble_esp32_param.ble_char1_WifiName_len = 8;
        memcpy(m_ble_esp32_param.ble_char1_WifiName,"441-2001",8);
    }
    if(!m_ble_esp32_param.ble_char2_WifiPassword_len)
    {
        m_ble_esp32_param.ble_char2_WifiPassword_len = 8;
        memcpy(m_ble_esp32_param.ble_char2_WifiPassword,"01155112",8);
    }
    if(!m_ble_esp32_param.ble_char3_IP_len)
    {
        m_ble_esp32_param.ble_char3_IP_len = 13;
        memcpy(m_ble_esp32_param.ble_char3_IP,"192.168.0.106",13);
    }
    if(!m_ble_esp32_param.ble_char4_Port_len)
    {
        m_ble_esp32_param.ble_char4_Port_len = 4;
        memcpy(m_ble_esp32_param.ble_char4_Port,"9898",4);
    }
    if(!m_ble_esp32_param.ble_char5_StaticIP_len)
    {
        m_ble_esp32_param.ble_char5_StaticIP_len = 13;
        memcpy(m_ble_esp32_param.ble_char5_StaticIP,"192.168.0.120",13);
    }


#ifdef usr_use_wifi_or_eth
    mWifi_init();
#else
    mEthernet_init();
#endif

    //socket_init();
    http_init();
}


